import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import babel from '@rollup/plugin-babel'
import typesrcript from '@rollup/plugin-typescript'
import less from 'rollup-plugin-less'
import clear from 'rollup-plugin-clear'
import terser from '@rollup/plugin-terser'
const env = process.env.NODE_ENV
const name = 'Rcs'

const config = {
    input: './src/index.ts',
    plugins: [
        json(),
        typesrcript({
            tsconfig: './tsconfig.json'
        }),
        less({
            output: './dist/lib/index.css'
        }),
        clear({
            target: ['lib']
        }),
        commonjs(),
        resolve(),
        babel({ babelHelpers: 'bundled' })
    ],
    output: [
        {
            format: 'cjs',
            file: './dist/index.cjs.js'
        },
        {
            format: 'es',
            file: './dist/index.es.js'
        },
        {
            format: 'umd',
            name: name,
            file: './dist/index.umd.js'
        }
    ]
}

// 判断环境, 生产环境开启压缩
if (env === 'production') {
    config.plugins.push(terser())
}

export default config
